#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time    : 2022/3/3 18:46
# @Author  : Ryu
# @Site    :
# @File    : test.py
# @Software: PyCharm

import base64
import os

def file_name(file_dir):
    L = []
    M = []
    for root, dirs, files in os.walk(file_dir):
        if dirs !=[]:
            for dir in dirs:
                flold = newdict(dir,Flase,root+"\\"+dir,"folder",[])
        print(root,dirs,files)


def setFile():
    with open('E:\main\\a.txt') as f:
        S=""
        for i in f:
            S=S+i
        print(S)


def test():
    result = os.path.split("E:\大三课程\java\实验报告\A")
    print(result)

def newdict(name="",fold="",path="",type="",children=[]):
    dict1 = {"name":name, "fold":fold, "path":path, "type":type, "children":children}
    return dict1

def collect():
    listFile=[]
    for filename in os.listdir(r'E:\大三课程\java\实验报告\A'):
        dictFile = {}
        dictFile["name"] = filename
        dictFile["path"] = "E:\大三课程\java\实验报告\A"+"\\"+filename
        if os.path.isdir("E:\大三课程\java\实验报告\A"+filename):
            dictFile["fold"]=True
        else:
            dictFile["fold"] = False
        listFile.append(dictFile)
    fileList = {"content": listFile}
    return fileList

#删除文件路径最后一个文件或文件夹
def delete_final_dir():
    path=r"E:\大三课程\java\实验报告\A\B"
    path = path.split("\\")
    path.pop()
    print("\\".join(path))
def sent():
    path = r"E:\大三课程\java\实验报告\A\B"
    a = "a"
    listFile = []
    listFile.append(path)
    listFile.append(a)
    print("\\".join(listFile))


def password():
    c = "123"
    c=c.encode("utf-8")
    a = base64.encodebytes(c)
    print(a.decode())
    b = base64.decodebytes(s)
    print(b)



def file_type():
    file_name, file_extension = os.path.splitext("abc.png")
    print(file_extension)
if __name__ =="__main__":
    # print(file_name("E:\大三课程\java\实验报告\A"))
    # file_name("E:\大三课程\java\实验报告\A")
    # print(newdict("a","b",'c',"d",[newdict("a","b",'c',"d",[newdict()])]))
    file_type()